package com.mew.lobby.handler.user;

import com.mew.common.dc.redis.UserProfileRedisService;
import com.mew.common.entity.user.Profile;
import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.bo.MewSession;
import com.mew.lobby.annotation.LobbyHandler;
import com.mew.lobby.message.response.AchievementResponseMessage;
import com.mew.lobby.net.LobbyHandlerMapCmdType;
import com.mew.lobby.net.MewHandler;
import com.zebra.remoting.config.EmptyMessage;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**成就
 * @author dylin
 * @create 2021/1/27 0027
 */
@Service
@Slf4j
@LobbyHandler(LobbyHandlerMapCmdType.Achievement)
public class AchievementHandler implements MewHandler<EmptyMessage> {
    @Autowired
    private UserProfileRedisService profileService;
    @Override
    public void handle(ZebraCommand<EmptyMessage> zebraCommand, MewSession session) {
        long userid = zebraCommand.getUserId();
        Profile profile=profileService.getRedisProfileById(userid);
        if(profile==null){
            zebraCommand.sendFailureCode(ResponseCode.LoginUn.code());
        }else{
            zebraCommand.sendMessage(AchievementResponseMessage
                    .builder()
                    .playTotal(profile.getPlayTotal())
                    .paymentTotal(profile.getPaymentTotal())
                    .build());
        }
    }
}
